package itcast.bos.base.service.imp;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import itcast.bos.base.dao.PromotionRespotory;
import itcast.bos.base.service.PromotionService;
import itcast.bos.domain.base.PageBean;
import itcast.bos.domain.base.Promotion;

@Service
@Transactional
public class PromotionServiceImp implements PromotionService {

	@Autowired
	private PromotionRespotory pr;

	@Override
	public void save(Promotion model) {
		pr.save(model);

	}

	@Override
	public Page<Promotion> findPageData(Pageable pa) {
		Page<Promotion> a = pr.findAll(pa);
		return a;
	}

	@Override
	public PageBean<Promotion> pageQuery(int page, int rows) {
		Pageable pageable = new PageRequest(page - 1, rows);
		Page<Promotion> pageData = pr.findAll(pageable);
		PageBean<Promotion> pagebean = new PageBean<>();
		pagebean.setPageData(pageData.getContent());
		pagebean.setTotalCount(pageData.getTotalElements());
		return pagebean;
	}

	@Override
	public Promotion FindOne(Integer id) {
		//int id1 = Integer.parseInt(id);
		return pr.findOne(id);
	}

	@Override
	public void updateStatus(Date date) {
	//	pr.updataStatus(date);
		
	}

}
